<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*" %>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="catcatcat.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">

</script>
</head>
<body>
<h1>使用 GET读取数据</h1>
<ul>
<li><p><b>用户名：</b>
   <%= request.getParameter("useid")%>
</p></li>
<li><p><b>您输入的密码：</b>
   <%= request.getParameter("pw")%>
</p></li>
</ul>

<%		
	String jiegg;
	try {
   		CaoZuoSql caoZuoSql=new CaoZuoSql();
		String pwd=request.getParameter("pw").trim();
		String pwsd=caoZuoSql.chaXunPwsd(request.getParameter("useid")).trim();
		out.println("获取的密码="+pwsd);
		caoZuoSql.guanBi();
		if(pwd.equals(pwsd)){
			//out.println("<p>登录结果：<span id='jieGuo'>登录成功</span></p>");
			jiegg="登录成功";
		}else if(!pwd.equals(pwsd)){
			//out.println("<p>登录结果：<span id='jieGuo'>登录失败</span></p>");
			jiegg="登录失败";
		}else{
			//out.println("<p>登录结果：<span id='jieGuo'>位置错误</span></p>");
			jiegg="位置错误";
		}
			// 重定向到新地址
		   //String site = new String("../index.html");
		   //response.setStatus(response.SC_MOVED_TEMPORARILY);
		   //response.setHeader("Location", site); 
	}catch (Exception e) {
		e.printStackTrace();
		//out.println("<p>登录结果：<span id='jieGuo'>没有你这只喵！</span></p>");
		jiegg="没有你这只喵";
	}
%>
<h1>登陆结果：</h1><h3 id="jieg"><%=jiegg %></h3>
<p>倒计时：--<span id="daoji">5</span></p>
<script  type="text/javascript">
var tt=document.getElementById("jieg");
var tg=tt.innerHTML;
alert(tg);
onload=function(){
    setInterval(go, 1000);
};

var x=5; //利用了全局变量来执行
function go(){
	if (tg=="登录成功") {
	    x--;
	    if(x>0){
	        document.getElementById("daoji").innerHTML=x;  //每次设置的x的值都不一样了。
	    }else{
	        location.href='http://127.0.0.1:9000';  // 设置你的注册页面
	    } 
	}else {
	    x--;
	    if(x>0){
	        document.getElementById("daoji").innerHTML=x;  //每次设置的x的值都不一样了。
	    }else{
	        location.href='http://localhost:8080/catcatcat/html/login2.html';  // 设置你的注册页面
	    }
	}
}  
</script>
</body>
</html>